package com.qf.blog.controller;

import com.qf.blog.auth.LoginThreadLocal;
import com.qf.blog.service.IDiscussPostService;
import com.qf.blog.service.impl.FollowerService;
import com.qf.blog.utils.Result;
import com.qf.blog.vo.StarsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class FollowerController {

    @Autowired
    private FollowerService followerService;

    @Autowired
    private IDiscussPostService postService;

    @RequestMapping("/follower/{userId}")
    public Result follower(@PathVariable Integer userId) {
        Integer loginUserId = LoginThreadLocal.get().getId();
        followerService.follower(loginUserId,userId.toString());
        return Result.success();
    }

    @RequestMapping("/stars")
    public Result starts (@RequestBody StarsVo starsVo){
        Integer loginUserId = LoginThreadLocal.get().getId();
        starsVo.setUserId(loginUserId);
        Map<String, Object> map = followerService.starts(starsVo);

        if(starsVo.getEntityType() == 1){
        postService.addComputeQueue(starsVo.getEntityId());
        }
        return Result.success(map);
    }

}
